package gui;

import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.text.ParseException;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.text.MaskFormatter;
import javax.swing.text.NumberFormatter;

/**
 * @author Ramy Refky 
 * */
public class ComponentPanel extends JPanel implements MouseListener,KeyListener {

	private static final long serialVersionUID = 1L;
	
	MainGui mg;
	
	JPanel basicPanel;
	JPanel ffPanel;
	JPanel otherPanel;
	
	AndComponentGraphics andComponentGraphics;
	NandComponentGraphics nandComponentGraphics;
	OrComponentGraphics orComponentGraphics;
	NorComponentGraphics norComponentGraphics;
	BufferComponentGraphics bufferComponentGraphics;
	NotComponentGraphics notComponentGraphics;
	XorComponentGraphics xorComponentGraphics;
	XnorComponentGraphics xnorComponentGraphics;
	TSBufferComponentGraphics tsbufferComponentGraphics;
	DFFComponentGraphics dffComponentGraphics;
	TFFComponentGraphics tffComponentGraphics;
	JKFFComponentGraphics jkffComponentGraphics;
	SRFFComponentGraphics srffComponentGraphics;
	CustomComponentGraphics customComponentGraphics;
	TextComponentGraphics textComponentGraphics;
	ModuleComponentGraphics moduleComponentGraphics;
	
	SplitterComponentGraphics splitterComponentGraphics;
	SplitterComponentGraphics splitterComponentGraphics2;
	GrouperComponentGraphics grouperComponentGraphics;
	GrouperComponentGraphics grouperComponentGraphics2;
	
	NodeComponentGraphics nodeComponentGraphics;
	NodeComponentGraphics nodeComponentGraphics2;
	NodeComponentGraphics nodeComponentGraphics3;
	
	JLabel andGateComponent;
	JLabel nandGateComponent;
	JLabel orGateComponent;
	JLabel norGateComponent;
	JLabel bufferGateComponent;
	JLabel notGateComponent;
	JLabel xorGateComponent;
	JLabel xnorGateComponent;
	JLabel tsbufferGateComponent;
	JLabel dffGateComponent;
	JLabel tffGateComponent;
	JLabel jkffGateComponent;
	JLabel srffGateComponent;
	JLabel customGateComponent;
	JLabel textGateComponent;
	JLabel moduleGateComponent;
	
	JLabel splitterGateComponent;
	JLabel grouperGateComponent;
	
	JLabel nodeGateComponent;
	JLabel nodeGateComponent2;
	JLabel nodeGateComponent3;
	
	JLabel andGateTrigger;
	JLabel nandGateTrigger;
	JLabel orGateTrigger;
	JLabel norGateTrigger;
	JLabel bufferGateTrigger;
	JLabel notGateTrigger;
	JLabel xorGateTrigger;
	JLabel xnorGateTrigger;
	
	JLabel splitterGateTrigger;
	JLabel grouperGateTrigger;
	
	JLabel andGateTransparentSheet;
	JLabel nandGateTransparentSheet;
	JLabel orGateTransparentSheet;
	JLabel norGateTransparentSheet;
	JLabel bufferGateTransparentSheet;
	JLabel notGateTransparentSheet;
	JLabel xorGateTransparentSheet;
	JLabel xnorGateTransparentSheet;
	JLabel tsbufferGateTransparentSheet;
	JLabel dffGateTransparentSheet;
	JLabel tffGateTransparentSheet;
	JLabel jkffGateTransparentSheet;
	JLabel srffGateTransparentSheet;
	JLabel customGateTransparentSheet;
	JLabel textGateTransparentSheet;
	JLabel moduleGateTransparentSheet;
	
	JLabel splitterGateTransparentSheet;
	JLabel grouperGateTransparentSheet;
	
	JLabel nodeGateTransparentSheet;
	JLabel nodeGateTransparentSheet2;
	JLabel nodeGateTransparentSheet3;
	
	JLabel andGateLabel;
	JLabel nandGateLabel;
	JLabel orGateLabel;
	JLabel norGateLabel;
	JLabel bufferGateLabel;
	JLabel notGateLabel;
	JLabel xorGateLabel;
	JLabel xnorGateLabel;
	JLabel tsbufferGateLabel;
	JLabel dffGateLabel;
	JLabel tffGateLabel;
	JLabel jkffGateLabel;
	JLabel srffGateLabel;
	JLabel customGateLabel;
	JLabel textGateLabel;
	JLabel moduleGateLabel;
	
	JLabel splitterGateLabel;
	JLabel grouperGateLabel;
	
	JLabel nodeGateLabel;
	JLabel nodeGateLabel2;
	JLabel nodeGateLabel3;
	
	JLabel andInputLabel;
	JLabel nandInputLabel;
	JLabel orInputLabel;
	JLabel norInputLabel;
	JLabel xorInputLabel;
	JLabel xnorInputLabel;
	
	JLabel splitterInputLabel;
	JLabel splitterOutputLabel;
	JLabel grouperInputLabel;
	JLabel grouperOutputLabel;
	
	JLabel nodeInputLabel;
	JLabel nodeInputLabel2;
	JLabel nodeInputLabel3;
	
	JLabel customInputLabel;
	JLabel customOutputLabel;
	JLabel customTitleLabel;
	JLabel customClockPinLabel;
	JCheckBox showCustomCheckBox;
	JLabel textTitleLabel;
	
	JButton moduleImportButton;
	JCheckBox showModuleImageCheckBox;
	File importedFile = null;
	
	JFormattedTextField andGateTextField;
	JFormattedTextField nandGateTextField;
	JFormattedTextField orGateTextField;
	JFormattedTextField norGateTextField;
	JFormattedTextField xorGateTextField;
	JFormattedTextField xnorGateTextField;
	JFormattedTextField customGateInputTextField;
	JFormattedTextField customGateOutputTextField;
	JFormattedTextField customGateTitleTextField;
	JFormattedTextField customGateClockPinTextField;
	JFormattedTextField textGateTitleTextField;
	
	JFormattedTextField nodeGateTextField;
	JFormattedTextField nodeGateTextField2;
	JFormattedTextField nodeGateTextField3;
	
	JFormattedTextField splitterGateInputTextField;
	JFormattedTextField splitterGateOutputTextField;
	JFormattedTextField grouperGateInputTextField;
	JFormattedTextField grouperGateOutputTextField;
	
	JLabel wireComponent;
	JLabel wireLabel;
	JLabel wireGraphics;
	
	JLabel wireComponent2;
	JLabel wireLabel2;
	JLabel wireGraphics2;
	
	JLabel wireComponent3;
	JLabel wireLabel3;
	JLabel wireGraphics3;
	
	int splitterGateInput;
	int splitterGateOutput;
	int grouperGateInput;
	int grouperGateOutput;
	
	/**
	 * Constructor initializes ComponentPanel buttons.
	 * @param MainGui
	 */
	public ComponentPanel(MainGui mg){
		
		setBounds(920,50,186,500);
		
		this.mg=mg;
		this.setBackground(Color.gray);
		setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		setVisible(true);
		setLayout(null);
		
		basicPanel= new JPanel();
		this.add(basicPanel);
		basicPanel.setBounds(4,4,178,492);
		basicPanel.setVisible(true);
		basicPanel.setLayout(null);
		basicPanel.setBackground(Color.gray);
		basicPanel.addMouseListener(this);
		
		ffPanel= new JPanel();
		this.add(ffPanel);
		ffPanel.setBounds(4,4,178,492);
		ffPanel.setVisible(false);
		ffPanel.setLayout(null);
		ffPanel.setBackground(Color.gray);
		ffPanel.addMouseListener(this);
		
		otherPanel= new JPanel();
		this.add(otherPanel);
		otherPanel.setBounds(4,4,178,492);
		otherPanel.setVisible(false);
		otherPanel.setLayout(null);
		otherPanel.setBackground(Color.gray);
		otherPanel.addMouseListener(this);
		
		initAndGateItems();
		initNandGateItems();
		hideNandGateItems();
		
		initOrGateItems();
		initNorGateItems();
		hideNorGateItems();
		
		initBufferGateItems();
		initNotGateItems();
		hideBufferGateItems();
		
		initXorGateItems();
		initXnorGateItems();
		hideXNorGateItems();
		
		initTSBufferGateItems();
		
		initDFFGateItems();
		initTFFGateItems();
		initJKFFGateItems();
		initSRFFGateItems();
		
		initCustomGateItems();
		initTextGateItems();
		initModuleGateItems();
		
		initNodeGateItems();
		initNodeGate2Items();
		initNodeGate3Items();
		
		initSplitterGateItems();
		initGrouperGateItems();
		hideGrouperGateItems();
		
		andGateTrigger= new JLabel();
		andGateTrigger.setBounds(0,10+164+6,14,25);
		andGateTrigger.setVisible(true);
		andGateTrigger.setOpaque(true);
		andGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
		andGateTrigger.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(andGateTrigger);
		andGateTrigger.addMouseListener(this);
		
		nandGateTrigger= new JLabel(" !");
		nandGateTrigger.setBounds(0,10+191+6,14,25);
		nandGateTrigger.setVisible(true);
		nandGateTrigger.setOpaque(true);
		nandGateTrigger.setBackground(Color.white);
		nandGateTrigger.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(nandGateTrigger);
		nandGateTrigger.addMouseListener(this);
		
		orGateTrigger= new JLabel();
		orGateTrigger.setBounds(0,10+234+6,14,25);
		orGateTrigger.setVisible(true);
		orGateTrigger.setOpaque(true);
		orGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
		orGateTrigger.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(orGateTrigger);
		orGateTrigger.addMouseListener(this);
		
		norGateTrigger= new JLabel(" !");
		norGateTrigger.setBounds(0,10+261+6,14,25);
		norGateTrigger.setVisible(true);
		norGateTrigger.setOpaque(true);
		norGateTrigger.setBackground(Color.white);
		norGateTrigger.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(norGateTrigger);
		norGateTrigger.addMouseListener(this);
		
		xorGateTrigger= new JLabel();
		xorGateTrigger.setBounds(0,10+304+6,14,25);
		xorGateTrigger.setVisible(true);
		xorGateTrigger.setOpaque(true);
		xorGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
		xorGateTrigger.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(xorGateTrigger);
		xorGateTrigger.addMouseListener(this);
		
		xnorGateTrigger= new JLabel(" !");
		xnorGateTrigger.setBounds(0,10+331+6,14,25);
		xnorGateTrigger.setVisible(true);
		xnorGateTrigger.setOpaque(true);
		xnorGateTrigger.setBackground(Color.white);
		xnorGateTrigger.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(xnorGateTrigger);
		xnorGateTrigger.addMouseListener(this);
		
		bufferGateTrigger= new JLabel();
		bufferGateTrigger.setBounds(0,10+94+6,14,25);
		bufferGateTrigger.setVisible(true);
		bufferGateTrigger.setOpaque(true);
		bufferGateTrigger.setBackground(Color.white);
		bufferGateTrigger.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(bufferGateTrigger);
		bufferGateTrigger.addMouseListener(this);
		
		notGateTrigger= new JLabel(" !");
		notGateTrigger.setBounds(0,10+121+6,14,25);
		notGateTrigger.setVisible(true);
		notGateTrigger.setOpaque(true);
		notGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
		notGateTrigger.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(notGateTrigger);
		notGateTrigger.addMouseListener(this);
		
		splitterGateTrigger= new JLabel();
		splitterGateTrigger.setBounds(0,10+419+6,14,25);
		splitterGateTrigger.setVisible(true);
		splitterGateTrigger.setOpaque(true);
		splitterGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
		splitterGateTrigger.setBorder(BorderFactory.createLineBorder(Color.black,3));
		otherPanel.add(splitterGateTrigger);
		splitterGateTrigger.addMouseListener(this);
		
		grouperGateTrigger= new JLabel(" !");
		grouperGateTrigger.setBounds(0,10+446+6,14,25);
		grouperGateTrigger.setVisible(true);
		grouperGateTrigger.setOpaque(true);
		grouperGateTrigger.setBackground(Color.white);
		grouperGateTrigger.setBorder(BorderFactory.createLineBorder(Color.black,3));
		otherPanel.add(grouperGateTrigger);
		grouperGateTrigger.addMouseListener(this);
		
		wireComponent = new JLabel();
		wireComponent.setBounds(16,15,90,30);
		wireComponent.setVisible(true);
		wireComponent.setOpaque(true);
		wireComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		wireComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		wireComponent.addMouseListener(this);
		basicPanel.add(wireComponent);
		
		wireLabel = new JLabel("Wire");
		wireLabel.setBounds(116,15,60,20);
		wireLabel.setForeground(Color.white);
		basicPanel.add(wireLabel);
		
		wireGraphics = new JLabel();
		wireGraphics.setBounds(15,13,60,4);
		wireGraphics.setVisible(true);
		wireGraphics.setOpaque(true);
		wireGraphics.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		wireGraphics.setBorder(BorderFactory.createLineBorder(Color.black,3));
		wireComponent.add(wireGraphics);
		
		wireComponent2 = new JLabel();
		wireComponent2.setBounds(16,15,90,30);
		wireComponent2.setVisible(true);
		wireComponent2.setOpaque(true);
		wireComponent2.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		wireComponent2.setBorder(BorderFactory.createLineBorder(Color.black,3));
		wireComponent2.addMouseListener(this);
		ffPanel.add(wireComponent2);
		
		wireLabel2 = new JLabel("Wire");
		wireLabel2.setBounds(116,15,60,20);
		wireLabel2.setForeground(Color.white);
		ffPanel.add(wireLabel2);
		
		wireGraphics2 = new JLabel();
		wireGraphics2.setBounds(15,13,60,4);
		wireGraphics2.setVisible(true);
		wireGraphics2.setOpaque(true);
		wireGraphics2.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		wireGraphics2.setBorder(BorderFactory.createLineBorder(Color.black,3));
		wireComponent2.add(wireGraphics2);
		
		wireComponent3 = new JLabel();
		wireComponent3.setBounds(16,15,90,30);
		wireComponent3.setVisible(true);
		wireComponent3.setOpaque(true);
		wireComponent3.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		wireComponent3.setBorder(BorderFactory.createLineBorder(Color.black,3));
		wireComponent3.addMouseListener(this);
		otherPanel.add(wireComponent3);
		
		wireLabel3 = new JLabel("Wire");
		wireLabel3.setBounds(116,15,60,20);
		wireLabel3.setForeground(Color.white);
		otherPanel.add(wireLabel3);
		
		wireGraphics3 = new JLabel();
		wireGraphics3.setBounds(15,13,60,4);
		wireGraphics3.setVisible(true);
		wireGraphics3.setOpaque(true);
		wireGraphics3.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		wireGraphics3.setBorder(BorderFactory.createLineBorder(Color.black,3));
		wireComponent3.add(wireGraphics3);
		
		repaint();
	}
	/**
	 * Gets the ComponentPanel's displayed AND Gate component.
	 * @return AndComponentGraphics
	 */
	public AndComponentGraphics getAndComponent(){
		return andComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed OR Gate component.
	 * @return OrComponentGraphics
	 */
	public OrComponentGraphics getOrComponent(){
		return orComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed NAND Gate component.
	 * @return NandComponentGraphics
	 */
	public NandComponentGraphics getNandComponent(){
		return nandComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed Nor Gate component.
	 * @return NorComponentGraphics
	 */
	public NorComponentGraphics getNorComponent(){
		return norComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed BUFFER Gate component.
	 * @return BufferComponentGraphics
	 */
	public BufferComponentGraphics getBufferComponent(){
		return bufferComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed NOT Gate component.
	 * @return NotComponentGraphics
	 */
	public NotComponentGraphics getNotComponent(){
		return notComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed XOR Gate component.
	 * @return XorComponentGraphics
	 */
	public XorComponentGraphics getXorComponent(){
		return xorComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed XNOR Gate component.
	 * @return XnorComponentGraphics
	 */
	public XnorComponentGraphics getXnorComponent(){
		return xnorComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed TRI-STATE BUFFER Gate component.
	 * @return TSBufferComponentGraphics
	 */
	public TSBufferComponentGraphics getTSBufferComponent(){
		return tsbufferComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed D-FLIP-FLOP Gate component.
	 * @return DFFComponentGraphics
	 */
	public DFFComponentGraphics getDFFComponent(){
		return dffComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed T-FLIP-FLOP Gate component.
	 * @return TFFComponentGraphics
	 */
	public TFFComponentGraphics getTFFComponent(){
		return tffComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed JK-FLIP-FLOP Gate component.
	 * @return JKFFComponentGraphics
	 */
	public JKFFComponentGraphics getJKFFComponent(){
		return jkffComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed SR-FLIP-FLOP Gate component.
	 * @return SRFFComponentGraphics
	 */
	public SRFFComponentGraphics getSRFFComponent(){
		return srffComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed Custom Gate component.
	 * @return CustomComponentGraphics
	 */
	public CustomComponentGraphics getCustomComponent(){
		return customComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed Text component.
	 * @return TextComponentGraphics
	 */
	public TextComponentGraphics getTextComponent(){
		return textComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed Module Gate component.
	 * @return ModuleComponentGraphics
	 */
	public ModuleComponentGraphics getModuleComponent(){
		return moduleComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed Node component in the BasicGates tab.
	 * @return NodeComponentGraphics
	 */
	public NodeComponentGraphics getNodeComponent(){
		return nodeComponentGraphics;
	}
	/**
	 * Gets the ComponentPanel's displayed Node component in the Flip-Flops tab.
	 * @return NodeComponentGraphics
	 */
	public NodeComponentGraphics getNodeComponent2(){
		return nodeComponentGraphics2;
	}
	/**
	 * Gets the ComponentPanel's displayed Node component in the Other tab.
	 * @return NodeComponentGraphics
	 */
	public NodeComponentGraphics getNodeComponent3(){
		return nodeComponentGraphics3;
	}
	/**
	 * Gets the ComponentPanel's displayed BasicGates tab.
	 * @return JPanel
	 */
	public JPanel getBasicPanel(){
		return basicPanel;
	}
	/**
	 * Gets the ComponentPanel's displayed Flip-Flops tab.
	 * @return JPanel
	 */
	public JPanel getFFPanel(){
		return ffPanel;
	}
	/**
	 * Gets the ComponentPanel's displayed Other tab.
	 * @return JPanel
	 */
	public JPanel getOtherPanel(){
		return otherPanel;
	}
	/**
	 * Draws the ComponentPanel's displayed AND Gate component with
	 * a given number of input ComponentPins. 
	 */
	public void drawAndGateComponent(int inputPinNumbers){
		
		andGateComponent.remove(andComponentGraphics);
		andComponentGraphics = new AndComponentGraphics(mg,15,10,60,40,inputPinNumbers);
		andGateComponent.add(andComponentGraphics);
		repaint();
	}
	/**
	 * Draws the ComponentPanel's displayed OR Gate component with
	 * a given number of input ComponentPins. 
	 */
	public void drawOrGateComponent(int inputPinNumbers){
		
		orGateComponent.remove(orComponentGraphics);
		orComponentGraphics = new OrComponentGraphics(mg,15,10,60,40,inputPinNumbers);
		orGateComponent.add(orComponentGraphics);
		repaint();
	}
	/**
	 * Draws the ComponentPanel's displayed NAND Gate component with
	 * a given number of input ComponentPins. 
	 */
	public void drawNandGateComponent(int inputPinNumbers){
		
		nandGateComponent.remove(nandComponentGraphics);
		nandComponentGraphics = new NandComponentGraphics(mg,15,10,60,40,inputPinNumbers);
		nandGateComponent.add(nandComponentGraphics);
		repaint();
	}
	/**
	 * Draws the ComponentPanel's displayed NOR Gate component with
	 * a given number of input ComponentPins. 
	 */
	public void drawNorGateComponent(int inputPinNumbers){
		
		norGateComponent.remove(norComponentGraphics);
		norComponentGraphics = new NorComponentGraphics(mg,15,10,60,40,inputPinNumbers);
		norGateComponent.add(norComponentGraphics);
		repaint();
	}
	/**
	 * Draws the ComponentPanel's displayed XOR Gate component with
	 * a given number of input ComponentPins. 
	 */
	public void drawXorGateComponent(int inputPinNumbers){
		
		xorGateComponent.remove(xorComponentGraphics);
		xorComponentGraphics = new XorComponentGraphics(mg,15,10,60,40,inputPinNumbers);
		xorGateComponent.add(xorComponentGraphics);
		repaint();
	}
	/**
	 * Draws the ComponentPanel's displayed XNOR Gate component with
	 * a given number of input ComponentPins. 
	 */
	public void drawXnorGateComponent(int inputPinNumbers){
		
		xnorGateComponent.remove(xnorComponentGraphics);
		xnorComponentGraphics = new XnorComponentGraphics(mg,15,10,60,40,inputPinNumbers);
		xnorGateComponent.add(xnorComponentGraphics);
		repaint();
	}
	/**
	 * Draws the ComponentPanel's displayed Custom Gate component with
	 * a given number of input and output ComponentPins, the gate's
	 * label, the clock pin, and a boolean value to toggle between showing
	 * and hiding its details. 
	 */
	public void drawCustomGateComponent(int inputPinNumbers,int outputPinNumbers,
			String text,int clockPin,boolean showDetails){
		
		customGateComponent.remove(customComponentGraphics);
		customComponentGraphics = new CustomComponentGraphics(mg,15,10,80,60,inputPinNumbers,
				outputPinNumbers,text,clockPin,showDetails);
		customComponentGraphics.setBounds(5,15,80,60);
		customGateComponent.add(customComponentGraphics);
		repaint();
	}
	/**
	 * Draws the ComponentPanel's displayed TEXT component with
	 * a given text String.
	 */
	public void drawTextGateComponent(String text){
		
		textGateComponent.remove(textComponentGraphics);
		textComponentGraphics = new TextComponentGraphics(mg,0,0,90,30,text);
		textGateComponent.add(textComponentGraphics);
		repaint();
	}
	/**
	 * Draws the ComponentPanel's displayed MODULE Gate component with
	 * a given File to import, and a boolean value to toggle between
	 * showing and hiding details.
	 */
	public void drawModuleGateComponent(File file,boolean showDetails){
		
		if(file!=null){
			moduleGateComponent.remove(moduleComponentGraphics);
			moduleComponentGraphics = new ModuleComponentGraphics(mg,5,10,80,60,file,showDetails);
			moduleGateComponent.add(moduleComponentGraphics);
			repaint();
		}
	}
	/**
	 * Draws the ComponentPanel's displayed NODE component in the BasicGates tab, with
	 * a given number of input and output ComponentPins. 
	 */
	public void drawNodeGateComponent(int inputPinNumbers){
		
		nodeGateComponent.remove(nodeComponentGraphics);
		nodeComponentGraphics = new NodeComponentGraphics(mg,40,10,10,10,inputPinNumbers,inputPinNumbers);
		nodeGateComponent.add(nodeComponentGraphics);
		repaint();
	}
	/**
	 * Draws the ComponentPanel's displayed NODE component in the Flip-Flops tab, with
	 * a given number of input and output ComponentPins. 
	 */
	public void drawNodeGate2Component(int inputPinNumbers){
		
		nodeGateComponent2.remove(nodeComponentGraphics2);
		nodeComponentGraphics2 = new NodeComponentGraphics(mg,40,10,10,10,inputPinNumbers,inputPinNumbers);
		nodeGateComponent2.add(nodeComponentGraphics2);
		repaint();
	}
	/**
	 * Draws the ComponentPanel's displayed NODE component in the Other tab, with
	 * a given number of input and output ComponentPins. 
	 */
	public void drawNodeGate3Component(int inputPinNumbers){
		
		nodeGateComponent3.remove(nodeComponentGraphics3);
		nodeComponentGraphics3 = new NodeComponentGraphics(mg,40,10,10,10,inputPinNumbers,inputPinNumbers);
		nodeGateComponent3.add(nodeComponentGraphics3);
		repaint();
	}
	/**
	 * Updates the number of output ComponentPins in the 
	 * ComponentPanel's displayed SPLITTER Gate.
	 */
	public void updateSplitterGateOutput(int value){
		splitterGateOutput=value;
	}
	/**
	 * Gets the number of output ComponentPins in the 
	 * ComponentPanel's displayed SPLITTER Gate.
	 * @return int
	 */
	public int getSplitterGateOutput(){
		return splitterGateOutput;
	}
	/**
	 * Updates the number of input ComponentPins in the 
	 * ComponentPanel's displayed SPLITTER Gate.
	 */
	public void updateSplitterGateInput(int value){
		splitterGateInput=value;
	}
	/**
	 * Gets the number of input ComponentPins in the 
	 * ComponentPanel's displayed SPLITTER Gate.
	 * @return int
	 */
	public int getSplitterGateInput(){
		return splitterGateInput;
	}
	/**
	 * Updates the number of output ComponentPins in the 
	 * ComponentPanel's displayed GROUPER Gate.
	 */
	public void updateGrouperGateOutput(int value){
		grouperGateOutput=value;
	}
	/**
	 * Gets the number of output ComponentPins in the 
	 * ComponentPanel's displayed GROUPER Gate.
	 * @return int
	 */
	public int getGrouperGateOutput(){
		return grouperGateOutput;
	}
	/**
	 * Updates the number of input ComponentPins in the 
	 * ComponentPanel's displayed GROUPER Gate.
	 */
	public void updateGrouperGateInput(int value){
		grouperGateInput=value;
	}
	/**
	 * Gets the number of input ComponentPins in the 
	 * ComponentPanel's displayed GROUPER Gate.
	 * @return int
	 */
	public int getGrouperGateInput(){
		return grouperGateInput;
	}
	/**
	 * Displays all ComponentPanel buttons to appear not selected.
	 */
	public void loseFocus(){
		
		wireComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		wireComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		wireComponent2.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		wireComponent2.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		wireComponent3.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		wireComponent3.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		andGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		andGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		nandGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		nandGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		orGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		orGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		norGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		norGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		bufferGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		bufferGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		notGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		notGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		xorGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		xorGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		xnorGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		xnorGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		tsbufferGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		tsbufferGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		nodeGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		nodeGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		nodeGateComponent2.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		nodeGateComponent2.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		nodeGateComponent3.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		nodeGateComponent3.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		dffGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		dffGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		tffGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		tffGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		jkffGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		jkffGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		srffGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		srffGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		customGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		customGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		textGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		textGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		moduleGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		moduleGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		splitterGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		splitterGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		
		grouperGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		grouperGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
	}
	/**
	 * Initializes the ComponentPanel's displayed AND Gate.
	 */
	public void initAndGateItems(){
		
		andGateComponent = new JLabel();
		andGateComponent.setBounds(10+6,10+160+6,90,60);
		andGateComponent.setVisible(true);
		andGateComponent.setOpaque(true);
		andGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		andGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(andGateComponent);
		
		andGateTransparentSheet = new JLabel();
		andGateTransparentSheet.setBounds(0,0,90,60);
		andGateTransparentSheet.setVisible(true);
		andGateTransparentSheet.addMouseListener(this);
		andGateComponent.add(andGateTransparentSheet);
		andGateComponent.setComponentZOrder(andGateTransparentSheet,0);
		
		andComponentGraphics = new AndComponentGraphics(mg,15,10,60,40,2);
		andGateComponent.add(andComponentGraphics);
		
		andGateLabel = new JLabel("And Gate");
		andGateLabel.setBounds(110+6,10+160+6,60,20);
		andGateLabel.setForeground(Color.white);
		basicPanel.add(andGateLabel);
		
		andInputLabel = new JLabel("Inputs");
		andInputLabel.setBounds(135+6,45+160+6,60,20);
		andInputLabel.setForeground(Color.lightGray);
		basicPanel.add(andInputLabel);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        andGateTextField = new JFormattedTextField(numF);
		andGateTextField.setBounds(110+6,45+160+6,20,20);
		andGateTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		andGateTextField.setValue(2);
		andGateTextField.selectAll();
		andGateTextField.addKeyListener(this);
		
		basicPanel.add(andGateTextField);
	}
	/**
	 * Initializes the ComponentPanel's displayed NAND Gate.
	 */
	public void initNandGateItems(){
		
		nandGateComponent = new JLabel();
		nandGateComponent.setBounds(10+6,10+160+6,90,60);
		nandGateComponent.setVisible(true);
		nandGateComponent.setOpaque(true);
		nandGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		nandGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(nandGateComponent);
		
		nandGateTransparentSheet = new JLabel();
		nandGateTransparentSheet.setBounds(0,0,90,60);
		nandGateTransparentSheet.setVisible(true);
		nandGateTransparentSheet.addMouseListener(this);
		nandGateComponent.add(nandGateTransparentSheet);
		nandGateComponent.setComponentZOrder(nandGateTransparentSheet,0);
		
		nandComponentGraphics = new NandComponentGraphics(mg,15,10,60,40,2);
		nandGateComponent.add(nandComponentGraphics);
		
		nandGateLabel = new JLabel("Nand Gate");
		nandGateLabel.setBounds(110+6,10+160+6,60,20);
		nandGateLabel.setForeground(Color.white);
		basicPanel.add(nandGateLabel);
		
		nandInputLabel = new JLabel("Inputs");
		nandInputLabel.setBounds(135+6,45+160+6,60,20);
		nandInputLabel.setForeground(Color.lightGray);
		basicPanel.add(nandInputLabel);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        nandGateTextField = new JFormattedTextField(numF);
		nandGateTextField.setBounds(110+6,45+160+6,20,20);
		nandGateTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		nandGateTextField.setValue(2);
		nandGateTextField.selectAll();
		nandGateTextField.addKeyListener(this);
		
		basicPanel.add(nandGateTextField);
	}
	/**
	 * Initializes the ComponentPanel's displayed OR Gate.
	 */
	public void initOrGateItems(){
		
		orGateComponent = new JLabel();
		orGateComponent.setBounds(10+6,10+230+6,90,60);
		orGateComponent.setVisible(true);
		orGateComponent.setOpaque(true);
		orGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		orGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(orGateComponent);
		
		orGateTransparentSheet = new JLabel();
		orGateTransparentSheet.setBounds(0,0,90,60);
		orGateTransparentSheet.setVisible(true);
		orGateTransparentSheet.addMouseListener(this);
		orGateComponent.add(orGateTransparentSheet);
		orGateComponent.setComponentZOrder(orGateTransparentSheet,0);
		
		orComponentGraphics = new OrComponentGraphics(mg,15,10,60,40,2);
		orGateComponent.add(orComponentGraphics);
		
		orGateLabel = new JLabel("Or Gate");
		orGateLabel.setBounds(110+6,10+230+6,60,20);
		orGateLabel.setForeground(Color.white);
		basicPanel.add(orGateLabel);
		
		orInputLabel = new JLabel("Inputs");
		orInputLabel.setBounds(135+6,45+230+6,60,20);
		orInputLabel.setForeground(Color.lightGray);
		basicPanel.add(orInputLabel);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        orGateTextField = new JFormattedTextField(numF);
		orGateTextField.setBounds(110+6,45+230+6,20,20);
		orGateTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		orGateTextField.setValue(2);
		orGateTextField.selectAll();
		orGateTextField.addKeyListener(this);
		
		basicPanel.add(orGateTextField);
	}
	/**
	 * Initializes the ComponentPanel's displayed NOR Gate.
	 */
	public void initNorGateItems(){
		
		norGateComponent = new JLabel();
		norGateComponent.setBounds(10+6,10+230+6,90,60);
		norGateComponent.setVisible(true);
		norGateComponent.setOpaque(true);
		norGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		norGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(norGateComponent);
		
		norGateTransparentSheet = new JLabel();
		norGateTransparentSheet.setBounds(0,0,90,60);
		norGateTransparentSheet.setVisible(true);
		norGateTransparentSheet.addMouseListener(this);
		norGateComponent.add(norGateTransparentSheet);
		norGateComponent.setComponentZOrder(norGateTransparentSheet,0);
		
		norComponentGraphics = new NorComponentGraphics(mg,15,10,60,40,2);
		norGateComponent.add(norComponentGraphics);
		
		norGateLabel = new JLabel("Nor Gate");
		norGateLabel.setBounds(110+6,10+230+6,60,20);
		norGateLabel.setForeground(Color.white);
		basicPanel.add(norGateLabel);
		
		norInputLabel = new JLabel("Inputs");
		norInputLabel.setBounds(135+6,45+230+6,60,20);
		norInputLabel.setForeground(Color.lightGray);
		basicPanel.add(norInputLabel);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        norGateTextField = new JFormattedTextField(numF);
		norGateTextField.setBounds(110+6,45+230+6,20,20);
		norGateTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		norGateTextField.setValue(2);
		norGateTextField.selectAll();
		norGateTextField.addKeyListener(this);
		
		basicPanel.add(norGateTextField);
	}
	/**
	 * Initializes the ComponentPanel's displayed BUFFER Gate.
	 */
	public void initBufferGateItems(){
		
		bufferGateComponent = new JLabel();
		bufferGateComponent.setBounds(10+6,10+90+6,90,60);
		bufferGateComponent.setVisible(true);
		bufferGateComponent.setOpaque(true);
		bufferGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		bufferGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(bufferGateComponent);
		
		bufferGateTransparentSheet = new JLabel();
		bufferGateTransparentSheet.setBounds(0,0,90,60);
		bufferGateTransparentSheet.setVisible(true);
		bufferGateTransparentSheet.addMouseListener(this);
		bufferGateComponent.add(bufferGateTransparentSheet);
		bufferGateComponent.setComponentZOrder(bufferGateTransparentSheet,0);
		
		bufferComponentGraphics = new BufferComponentGraphics(mg,15,10,60,40,2);
		bufferGateComponent.add(bufferComponentGraphics);
		
		bufferGateLabel = new JLabel("Buffer");
		bufferGateLabel.setBounds(110+6,10+90+6,60,20);
		bufferGateLabel.setForeground(Color.white);
		basicPanel.add(bufferGateLabel);
	}
	/**
	 * Initializes the ComponentPanel's displayed NOT Gate.
	 */
	public void initNotGateItems(){
		
		notGateComponent = new JLabel();
		notGateComponent.setBounds(10+6,10+90+6,90,60);
		notGateComponent.setVisible(true);
		notGateComponent.setOpaque(true);
		notGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		notGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(notGateComponent);
		
		notGateTransparentSheet = new JLabel();
		notGateTransparentSheet.setBounds(0,0,90,60);
		notGateTransparentSheet.setVisible(true);
		notGateTransparentSheet.addMouseListener(this);
		notGateComponent.add(notGateTransparentSheet);
		notGateComponent.setComponentZOrder(notGateTransparentSheet,0);
		
		notComponentGraphics = new NotComponentGraphics(mg,15,10,60,40,2);
		notGateComponent.add(notComponentGraphics);
		
		notGateLabel = new JLabel("Not Gate");
		notGateLabel.setBounds(110+6,10+90+6,60,20);
		notGateLabel.setForeground(Color.white);
		basicPanel.add(notGateLabel);
	}
	/**
	 * Initializes the ComponentPanel's displayed XOR Gate.
	 */
	public void initXorGateItems(){
		
		xorGateComponent = new JLabel();
		xorGateComponent.setBounds(10+6,10+300+6,90,60);
		xorGateComponent.setVisible(true);
		xorGateComponent.setOpaque(true);
		xorGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		xorGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(xorGateComponent);
		
		xorGateTransparentSheet = new JLabel();
		xorGateTransparentSheet.setBounds(0,0,90,60);
		xorGateTransparentSheet.setVisible(true);
		xorGateTransparentSheet.addMouseListener(this);
		xorGateComponent.add(xorGateTransparentSheet);
		xorGateComponent.setComponentZOrder(xorGateTransparentSheet,0);
		
		xorComponentGraphics = new XorComponentGraphics(mg,15,10,60,40,2);
		xorGateComponent.add(xorComponentGraphics);
		
		xorGateLabel = new JLabel("Xor Gate");
		xorGateLabel.setBounds(110+6,10+300+6,60,20);
		xorGateLabel.setForeground(Color.white);
		basicPanel.add(xorGateLabel);
		
		xorInputLabel = new JLabel("Inputs");
		xorInputLabel.setBounds(135+6,45+300+6,60,20);
		xorInputLabel.setForeground(Color.lightGray);
		basicPanel.add(xorInputLabel);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        xorGateTextField = new JFormattedTextField(numF);
		xorGateTextField.setBounds(110+6,45+300+6,20,20);
		xorGateTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		xorGateTextField.setValue(2);
		xorGateTextField.selectAll();
		xorGateTextField.addKeyListener(this);
		
		basicPanel.add(xorGateTextField);
	}
	/**
	 * Initializes the ComponentPanel's displayed XNOR Gate.
	 */
	public void initXnorGateItems(){
		
		xnorGateComponent = new JLabel();
		xnorGateComponent.setBounds(10+6,10+300+6,90,60);
		xnorGateComponent.setVisible(true);
		xnorGateComponent.setOpaque(true);
		xnorGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		xnorGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(xnorGateComponent);
		
		xnorGateTransparentSheet = new JLabel();
		xnorGateTransparentSheet.setBounds(0,0,90,60);
		xnorGateTransparentSheet.setVisible(true);
		xnorGateTransparentSheet.addMouseListener(this);
		xnorGateComponent.add(xnorGateTransparentSheet);
		xnorGateComponent.setComponentZOrder(xnorGateTransparentSheet,0);
		
		xnorComponentGraphics = new XnorComponentGraphics(mg,15,10,60,40,2);
		xnorGateComponent.add(xnorComponentGraphics);
		
		xnorGateLabel = new JLabel("XNor Gate");
		xnorGateLabel.setBounds(110+6,10+300+6,60,20);
		xnorGateLabel.setForeground(Color.white);
		basicPanel.add(xnorGateLabel);
		
		xnorInputLabel = new JLabel("Inputs");
		xnorInputLabel.setBounds(135+6,45+300+6,60,20);
		xnorInputLabel.setForeground(Color.lightGray);
		basicPanel.add(xnorInputLabel);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        xnorGateTextField = new JFormattedTextField(numF);
		xnorGateTextField.setBounds(110+6,45+300+6,20,20);
		xnorGateTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		xnorGateTextField.setValue(2);
		xnorGateTextField.selectAll();
		xnorGateTextField.addKeyListener(this);
		
		basicPanel.add(xnorGateTextField);
	}
	/**
	 * Initializes the ComponentPanel's displayed TRI-STATE-BUFFER Gate.
	 */
	public void initTSBufferGateItems(){
		
		tsbufferGateComponent = new JLabel();
		tsbufferGateComponent.setBounds(10+6,10+370+6,90,60);
		tsbufferGateComponent.setVisible(true);
		tsbufferGateComponent.setOpaque(true);
		tsbufferGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		tsbufferGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(tsbufferGateComponent);
		
		tsbufferGateTransparentSheet = new JLabel();
		tsbufferGateTransparentSheet.setBounds(0,0,90,60);
		tsbufferGateTransparentSheet.setVisible(true);
		tsbufferGateTransparentSheet.addMouseListener(this);
		tsbufferGateComponent.add(tsbufferGateTransparentSheet);
		tsbufferGateComponent.setComponentZOrder(tsbufferGateTransparentSheet,0);
		
		tsbufferComponentGraphics = new TSBufferComponentGraphics(mg,15,10,60,40,2);
		tsbufferGateComponent.add(tsbufferComponentGraphics);
		
		tsbufferGateLabel = new JLabel("TS-Buffer");
		tsbufferGateLabel.setBounds(110+6,10+370+6,60,20);
		tsbufferGateLabel.setForeground(Color.white);
		basicPanel.add(tsbufferGateLabel);
	}
	/**
	 * Initializes the ComponentPanel's displayed D-FLIP-FLOP Gate.
	 */
	public void initDFFGateItems(){
		
		dffGateComponent = new JLabel();
		dffGateComponent.setBounds(10+6,10+100,90,60);
		dffGateComponent.setVisible(true);
		dffGateComponent.setOpaque(true);
		dffGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		dffGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		ffPanel.add(dffGateComponent);
		
		dffGateTransparentSheet = new JLabel();
		dffGateTransparentSheet.setBounds(0,0,90,60);
		dffGateTransparentSheet.setVisible(true);
		dffGateTransparentSheet.addMouseListener(this);
		dffGateComponent.add(dffGateTransparentSheet);
		dffGateComponent.setComponentZOrder(dffGateTransparentSheet,0);
		
		dffComponentGraphics = new DFFComponentGraphics(mg,15,10,60,40,2,2);
		dffGateComponent.add(dffComponentGraphics);
		
		dffGateLabel = new JLabel("D Flip-Flop");
		dffGateLabel.setBounds(110+6,10+100,60,20);
		dffGateLabel.setForeground(Color.white);
		ffPanel.add(dffGateLabel);
	}
	/**
	 * Initializes the ComponentPanel's displayed T-FLIP-FLOP Gate.
	 */
	public void initTFFGateItems(){
		
		tffGateComponent = new JLabel();
		tffGateComponent.setBounds(10+6,10+180,90,60);
		tffGateComponent.setVisible(true);
		tffGateComponent.setOpaque(true);
		tffGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		tffGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		ffPanel.add(tffGateComponent);
		
		tffGateTransparentSheet = new JLabel();
		tffGateTransparentSheet.setBounds(0,0,90,60);
		tffGateTransparentSheet.setVisible(true);
		tffGateTransparentSheet.addMouseListener(this);
		tffGateComponent.add(tffGateTransparentSheet);
		tffGateComponent.setComponentZOrder(tffGateTransparentSheet,0);
		
		tffComponentGraphics = new TFFComponentGraphics(mg,15,10,60,40,2,2);
		tffGateComponent.add(tffComponentGraphics);
		
		tffGateLabel = new JLabel("T Flip-Flop");
		tffGateLabel.setBounds(110+6,10+180,60,20);
		tffGateLabel.setForeground(Color.white);
		ffPanel.add(tffGateLabel);
	}
	/**
	 * Initializes the ComponentPanel's displayed JK-FLIP-FLOP Gate.
	 */
	public void initJKFFGateItems(){
		
		jkffGateComponent = new JLabel();
		jkffGateComponent.setBounds(10+6,10+260,90,60);
		jkffGateComponent.setVisible(true);
		jkffGateComponent.setOpaque(true);
		jkffGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		jkffGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		ffPanel.add(jkffGateComponent);
		
		jkffGateTransparentSheet = new JLabel();
		jkffGateTransparentSheet.setBounds(0,0,90,60);
		jkffGateTransparentSheet.setVisible(true);
		jkffGateTransparentSheet.addMouseListener(this);
		jkffGateComponent.add(jkffGateTransparentSheet);
		jkffGateComponent.setComponentZOrder(jkffGateTransparentSheet,0);
		
		jkffComponentGraphics = new JKFFComponentGraphics(mg,15,10,80,40,3,2);
		jkffComponentGraphics.setBounds(5,10,80,40);
		jkffGateComponent.add(jkffComponentGraphics);
		
		jkffGateLabel = new JLabel("JK Flip-Flop");
		jkffGateLabel.setBounds(110+3,10+260,65,20);
		jkffGateLabel.setForeground(Color.white);
		ffPanel.add(jkffGateLabel);
	}
	/**
	 * Initializes the ComponentPanel's displayed SR-FLIP-FLOP Gate.
	 */
	public void initSRFFGateItems(){
		
		srffGateComponent = new JLabel();
		srffGateComponent.setBounds(10+6,10+340,90,60);
		srffGateComponent.setVisible(true);
		srffGateComponent.setOpaque(true);
		srffGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		srffGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		ffPanel.add(srffGateComponent);
		
		srffGateTransparentSheet = new JLabel();
		srffGateTransparentSheet.setBounds(0,0,90,60);
		srffGateTransparentSheet.setVisible(true);
		srffGateTransparentSheet.addMouseListener(this);
		srffGateComponent.add(srffGateTransparentSheet);
		srffGateComponent.setComponentZOrder(srffGateTransparentSheet,0);
		
		srffComponentGraphics = new SRFFComponentGraphics(mg,15,10,80,40,3,2);
		srffComponentGraphics.setBounds(5,10,80,40);
		srffGateComponent.add(srffComponentGraphics);
		
		srffGateLabel = new JLabel("SR Flip-Flop");
		srffGateLabel.setBounds(110+3,10+340,65,20);
		srffGateLabel.setForeground(Color.white);
		ffPanel.add(srffGateLabel);
	}
	/**
	 * Initializes the ComponentPanel's displayed CUSTOM Gate.
	 */
	public void initCustomGateItems(){
		
		customGateComponent = new JLabel();
		customGateComponent.setBounds(10+6,10+160-10,90,90);
		customGateComponent.setVisible(true);
		customGateComponent.setOpaque(true);
		customGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		customGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		otherPanel.add(customGateComponent);
		
		customGateTransparentSheet = new JLabel();
		customGateTransparentSheet.setBounds(0,0,90,90);
		customGateTransparentSheet.setVisible(true);
		customGateTransparentSheet.addMouseListener(this);
		customGateComponent.add(customGateTransparentSheet);
		customGateComponent.setComponentZOrder(customGateTransparentSheet,0);
		
		customComponentGraphics = new CustomComponentGraphics(mg,15,10,80,60,2,2,"Custom",0,true);
		customComponentGraphics.setBounds(5,15,80,60);
		customGateComponent.add(customComponentGraphics);
		
		customGateLabel = new JLabel("Custom");
		customGateLabel.setBounds(110+6,10+160-10,60,20);
		customGateLabel.setForeground(Color.white);
		otherPanel.add(customGateLabel);
		
		customInputLabel = new JLabel("Inputs");
		customInputLabel.setBounds(135+1,45+155-10,60,20);
		customInputLabel.setForeground(Color.lightGray);
		otherPanel.add(customInputLabel);
		
		customOutputLabel = new JLabel("Outputs");
		customOutputLabel.setBounds(134,45+185-10,60,20);
		customOutputLabel.setForeground(Color.lightGray);
		otherPanel.add(customOutputLabel);
		
		customTitleLabel = new JLabel("Name:");
		customTitleLabel.setBounds(50+20,45+215-10,40,20);
		customTitleLabel.setForeground(Color.lightGray);
		otherPanel.add(customTitleLabel);
		
		customClockPinLabel = new JLabel("Clock pin:");
		customClockPinLabel.setBounds(50+20,45+242-10,55,20);
		customClockPinLabel.setForeground(Color.lightGray);
		otherPanel.add(customClockPinLabel);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        NumberFormatter numF2 = new NumberFormatter();
		numF2.setAllowsInvalid(false);
		numF2.setOverwriteMode(true);
		numF2.setMinimum(0);
        numF2.setMaximum(new Integer(99));
        
        customGateInputTextField = new JFormattedTextField(numF);
		customGateInputTextField.setBounds(110+2,45+155-10,20,20);
		customGateInputTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		customGateInputTextField.setValue(2);
		customGateInputTextField.selectAll();
		customGateInputTextField.addKeyListener(this);
		
		otherPanel.add(customGateInputTextField);
		
        customGateOutputTextField = new JFormattedTextField(numF);
		customGateOutputTextField.setBounds(110+2,45+185-10,20,20);
		customGateOutputTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		customGateOutputTextField.setValue(2);
		customGateOutputTextField.selectAll();
		customGateOutputTextField.addKeyListener(this);
		
		otherPanel.add(customGateOutputTextField);
		
		try {
			customGateTitleTextField = new JFormattedTextField(new MaskFormatter("********"));
		} catch (ParseException e) {}
		customGateTitleTextField.setBounds(110+2,45+215-10,65,20);
		customGateTitleTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		customGateTitleTextField.setValue("Custom");
		customGateTitleTextField.selectAll();
		customGateTitleTextField.addKeyListener(this);
		
		otherPanel.add(customGateTitleTextField);
		
		customGateClockPinTextField = new JFormattedTextField(numF2);
		customGateClockPinTextField.setBounds(130+2,45+242-10,20,20);
		customGateClockPinTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		customGateClockPinTextField.setValue(0);
		customGateClockPinTextField.selectAll();
		customGateClockPinTextField.addKeyListener(this);
		
		otherPanel.add(customGateClockPinTextField);
		
		showCustomCheckBox = new JCheckBox();
		showCustomCheckBox.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		showCustomCheckBox.setBounds(70,45+270-10,20,15);
		showCustomCheckBox.setSelected(true);
		showCustomCheckBox.addMouseListener(this);
		otherPanel.add(showCustomCheckBox);
		
		JLabel customDetailsLabel =new JLabel("Details",JLabel.CENTER);
		customDetailsLabel.setBounds(92,45+270-10,40,15);
		customDetailsLabel.setForeground(Color.lightGray);
		otherPanel.add(customDetailsLabel);
		
	}
	/**
	 * Initializes the ComponentPanel's displayed TEXT component.
	 */
	public void initTextGateItems(){
		
		textGateComponent = new JLabel();
		textGateComponent.setBounds(10+6,10+90,90,30);
		textGateComponent.setVisible(true);
		textGateComponent.setOpaque(true);
		textGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		textGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		otherPanel.add(textGateComponent);
		
		textGateTransparentSheet = new JLabel();
		textGateTransparentSheet.setBounds(0,0,90,90);
		textGateTransparentSheet.setVisible(true);
		textGateTransparentSheet.addMouseListener(this);
		textGateComponent.add(textGateTransparentSheet);
		textGateComponent.setComponentZOrder(textGateTransparentSheet,0);
		
		textComponentGraphics = new TextComponentGraphics(mg,0,0,90,25,"\"text\"");
		textGateComponent.add(textComponentGraphics);
		
		textGateLabel = new JLabel("Label");
		textGateLabel.setBounds(110+6,10+90,60,20);
		textGateLabel.setForeground(Color.white);
		otherPanel.add(textGateLabel);
		
		textTitleLabel = new JLabel("Text:");
		textTitleLabel.setBounds(50+25,45+82,40,20);
		textTitleLabel.setForeground(Color.lightGray);
		otherPanel.add(textTitleLabel);
        
		try {
			textGateTitleTextField = new JFormattedTextField(new MaskFormatter("********"));
		} catch (ParseException e) {}
		textGateTitleTextField.setBounds(110+2,45+80,65,20);
		textGateTitleTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		textGateTitleTextField.setValue("\"text\"");
		textGateTitleTextField.selectAll();
		textGateTitleTextField.addKeyListener(this);
		
		otherPanel.add(textGateTitleTextField);
	}
	/**
	 * Initializes the ComponentPanel's displayed MODULE Gate.
	 */
	public void initModuleGateItems(){
		
		moduleGateComponent = new JLabel();
		moduleGateComponent.setBounds(10+6,10+345-25,90,90);
		moduleGateComponent.setVisible(true);
		moduleGateComponent.setOpaque(true);
		moduleGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		moduleGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		otherPanel.add(moduleGateComponent);
		
		moduleGateTransparentSheet = new JLabel();
		moduleGateTransparentSheet.setBounds(0,0,90,90);
		moduleGateTransparentSheet.setVisible(true);
		moduleGateTransparentSheet.addMouseListener(this);
		moduleGateComponent.add(moduleGateTransparentSheet);
		moduleGateComponent.setComponentZOrder(moduleGateTransparentSheet,0);
		
		moduleComponentGraphics = new ModuleComponentGraphics(mg,15,10,80,60,null,false);
		moduleComponentGraphics.setBounds(5,15,80,60);
		moduleGateComponent.add(moduleComponentGraphics);
		
		moduleGateLabel = new JLabel("Module");
		moduleGateLabel.setBounds(110+6,10+345-25,60,20);
		moduleGateLabel.setForeground(Color.white);
		otherPanel.add(moduleGateLabel);
		
		moduleImportButton= new JButton();
		moduleImportButton.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		moduleImportButton.setBounds(107,10+375-25,71,30);
		JLabel moduleImportLabel =new JLabel("Import",JLabel.CENTER);
		moduleImportButton.add(moduleImportLabel);
		moduleImportButton.addMouseListener(this);
		otherPanel.add(moduleImportButton);
		
		showModuleImageCheckBox = new JCheckBox();
		showModuleImageCheckBox.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		showModuleImageCheckBox.setBounds(110,10+415-25,20,15);
		showModuleImageCheckBox.setSelected(true);
		showModuleImageCheckBox.addMouseListener(this);
		otherPanel.add(showModuleImageCheckBox);
		
		JLabel moduleDetailsLabel =new JLabel("Details",JLabel.CENTER);
		moduleDetailsLabel.setBounds(132,10+415-25,40,15);
		moduleDetailsLabel.setForeground(Color.lightGray);
		otherPanel.add(moduleDetailsLabel);
		
	}
	/**
	 * Initializes the ComponentPanel's displayed Node component in the BasicGates tab.
	 */
	public void initNodeGateItems(){
		nodeGateComponent = new JLabel();
		nodeGateComponent.setBounds(16,55,90,30);
		nodeGateComponent.setVisible(true);
		nodeGateComponent.setOpaque(true);
		nodeGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		nodeGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		basicPanel.add(nodeGateComponent);
		
		nodeGateTransparentSheet = new JLabel();
		nodeGateTransparentSheet.setBounds(0,0,90,30);
		nodeGateTransparentSheet.setVisible(true);
		nodeGateTransparentSheet.addMouseListener(this);
		nodeGateComponent.add(nodeGateTransparentSheet);
		nodeGateComponent.setComponentZOrder(nodeGateTransparentSheet,0);
		
		nodeComponentGraphics = new NodeComponentGraphics(mg,40,10,10,10,1,1);
		nodeGateComponent.add(nodeComponentGraphics);
		
		nodeGateLabel = new JLabel("Node");
		nodeGateLabel.setBounds(116,55,60,20);
		nodeGateLabel.setForeground(Color.white);
		basicPanel.add(nodeGateLabel);
		
		nodeInputLabel = new JLabel("In/Out");
		nodeInputLabel.setBounds(135+6,75,60,20);
		nodeInputLabel.setForeground(Color.lightGray);
		basicPanel.add(nodeInputLabel);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        nodeGateTextField = new JFormattedTextField(numF);
		nodeGateTextField.setBounds(110+6,77,20,20);
		nodeGateTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		nodeGateTextField.setValue(1);
		nodeGateTextField.selectAll();
		nodeGateTextField.addKeyListener(this);
		
		basicPanel.add(nodeGateTextField);
	}
	/**
	 * Initializes the ComponentPanel's displayed Node component in the Flip-Flops tab.
	 */
	public void initNodeGate2Items(){
		nodeGateComponent2 = new JLabel();
		nodeGateComponent2.setBounds(16,55,90,30);
		nodeGateComponent2.setVisible(true);
		nodeGateComponent2.setOpaque(true);
		nodeGateComponent2.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		nodeGateComponent2.setBorder(BorderFactory.createLineBorder(Color.black,3));
		ffPanel.add(nodeGateComponent2);
		
		nodeGateTransparentSheet2 = new JLabel();
		nodeGateTransparentSheet2.setBounds(0,0,90,30);
		nodeGateTransparentSheet2.setVisible(true);
		nodeGateTransparentSheet2.addMouseListener(this);
		nodeGateComponent2.add(nodeGateTransparentSheet2);
		nodeGateComponent2.setComponentZOrder(nodeGateTransparentSheet2,0);
		
		nodeComponentGraphics2 = new NodeComponentGraphics(mg,40,10,10,10,1,1);
		nodeGateComponent2.add(nodeComponentGraphics2);
		
		nodeGateLabel2 = new JLabel("Node");
		nodeGateLabel2.setBounds(116,55,60,20);
		nodeGateLabel2.setForeground(Color.white);
		ffPanel.add(nodeGateLabel2);
		
		nodeInputLabel2 = new JLabel("In/Out");
		nodeInputLabel2.setBounds(135+6,75,60,20);
		nodeInputLabel2.setForeground(Color.lightGray);
		ffPanel.add(nodeInputLabel2);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        nodeGateTextField2 = new JFormattedTextField(numF);
		nodeGateTextField2.setBounds(110+6,77,20,20);
		nodeGateTextField2.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		nodeGateTextField2.setValue(1);
		nodeGateTextField2.selectAll();
		nodeGateTextField2.addKeyListener(this);
		
		ffPanel.add(nodeGateTextField2);
	}
	/**
	 * Initializes the ComponentPanel's displayed Node component in the Others tab.
	 */
	public void initNodeGate3Items(){
		nodeGateComponent3 = new JLabel();
		nodeGateComponent3.setBounds(16,55,90,30);
		nodeGateComponent3.setVisible(true);
		nodeGateComponent3.setOpaque(true);
		nodeGateComponent3.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		nodeGateComponent3.setBorder(BorderFactory.createLineBorder(Color.black,3));
		otherPanel.add(nodeGateComponent3);
		
		nodeGateTransparentSheet3 = new JLabel();
		nodeGateTransparentSheet3.setBounds(0,0,90,30);
		nodeGateTransparentSheet3.setVisible(true);
		nodeGateTransparentSheet3.addMouseListener(this);
		nodeGateComponent3.add(nodeGateTransparentSheet3);
		nodeGateComponent3.setComponentZOrder(nodeGateTransparentSheet3,0);
		
		nodeComponentGraphics3 = new NodeComponentGraphics(mg,40,10,10,10,1,1);
		nodeGateComponent3.add(nodeComponentGraphics3);
		
		nodeGateLabel3 = new JLabel("Node");
		nodeGateLabel3.setBounds(116,55,60,20);
		nodeGateLabel3.setForeground(Color.white);
		otherPanel.add(nodeGateLabel3);
		
		nodeInputLabel3 = new JLabel("In/Out");
		nodeInputLabel3.setBounds(135+6,75,60,20);
		nodeInputLabel3.setForeground(Color.lightGray);
		otherPanel.add(nodeInputLabel3);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        nodeGateTextField3 = new JFormattedTextField(numF);
		nodeGateTextField3.setBounds(110+6,77,20,20);
		nodeGateTextField3.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		nodeGateTextField3.setValue(1);
		nodeGateTextField3.selectAll();
		nodeGateTextField3.addKeyListener(this);
		
		otherPanel.add(nodeGateTextField3);
	}
	/**
	 * Initializes the ComponentPanel's displayed SPLITTER Gate.
	 */
	public void initSplitterGateItems(){
		splitterGateComponent = new JLabel();
		splitterGateComponent.setBounds(10+6,10+440+6-15,90,40);
		splitterGateComponent.setVisible(true);
		splitterGateComponent.setOpaque(true);
		splitterGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		splitterGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		otherPanel.add(splitterGateComponent);
		
		splitterGateTransparentSheet = new JLabel();
		splitterGateTransparentSheet.setBounds(0,0,90,60);
		splitterGateTransparentSheet.setVisible(true);
		splitterGateTransparentSheet.addMouseListener(this);
		splitterGateComponent.add(splitterGateTransparentSheet);
		splitterGateComponent.setComponentZOrder(splitterGateTransparentSheet,0);
		
		splitterComponentGraphics = new SplitterComponentGraphics(mg,15,-10,60,60,18,9,1);
		splitterGateComponent.add(splitterComponentGraphics);
		
		splitterComponentGraphics2 = new SplitterComponentGraphics(mg,15,-10,60,60,18,9,2);
		splitterGateComponent.add(splitterComponentGraphics2);
		
		splitterGateLabel = new JLabel("Splitter");
		splitterGateLabel.setBounds(110+6,10+430-15,60,20);
		splitterGateLabel.setForeground(Color.white);
		otherPanel.add(splitterGateLabel);
		
		splitterInputLabel = new JLabel("Inputs");
		splitterInputLabel.setBounds(130,45+395+6,60,20);
		splitterInputLabel.setForeground(Color.lightGray);
		otherPanel.add(splitterInputLabel);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        splitterGateInputTextField = new JFormattedTextField(numF);
		splitterGateInputTextField.setBounds(108,45+395+6,20,20);
		splitterGateInputTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		splitterGateInputTextField.setValue(2);
		splitterGateInputTextField.selectAll();
		splitterGateInputTextField.addKeyListener(this);
		
		updateSplitterGateInput(2);
		
		otherPanel.add(splitterGateInputTextField);
		
		splitterOutputLabel = new JLabel("Split-Top");
		splitterOutputLabel.setBounds(128,45+420+6,60,20);
		splitterOutputLabel.setForeground(Color.lightGray);
		otherPanel.add(splitterOutputLabel);
		
        splitterGateOutputTextField = new JFormattedTextField(numF);
		splitterGateOutputTextField.setBounds(108,45+420+6,20,20);
		splitterGateOutputTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		splitterGateOutputTextField.setValue(1);
		splitterGateOutputTextField.selectAll();
		splitterGateOutputTextField.addKeyListener(this);
		
		updateSplitterGateOutput(1);
		
		otherPanel.add(splitterGateOutputTextField);
	}
	/**
	 * Initializes the ComponentPanel's displayed GROUPER Gate.
	 */
	public void initGrouperGateItems(){
		grouperGateComponent = new JLabel();
		grouperGateComponent.setBounds(10+6,10+440+6-15,90,40);
		grouperGateComponent.setVisible(true);
		grouperGateComponent.setOpaque(true);
		grouperGateComponent.setBackground(Color.getHSBColor((float)0.1,(float)0.05,(float)0.9));
		grouperGateComponent.setBorder(BorderFactory.createLineBorder(Color.black,3));
		otherPanel.add(grouperGateComponent);
		
		grouperGateTransparentSheet = new JLabel();
		grouperGateTransparentSheet.setBounds(0,0,90,60);
		grouperGateTransparentSheet.setVisible(true);
		grouperGateTransparentSheet.addMouseListener(this);
		grouperGateComponent.add(grouperGateTransparentSheet);
		grouperGateComponent.setComponentZOrder(grouperGateTransparentSheet,0);
		
		grouperComponentGraphics = new GrouperComponentGraphics(mg,15,-10,60,60,18,9,1);
		grouperGateComponent.add(grouperComponentGraphics);
		
		grouperComponentGraphics2 = new GrouperComponentGraphics(mg,15,-10,60,60,18,9,2);
		grouperGateComponent.add(grouperComponentGraphics2);
		
		grouperGateLabel = new JLabel("Grouper");
		grouperGateLabel.setBounds(110+6,10+430-15,60,20);
		grouperGateLabel.setForeground(Color.white);
		otherPanel.add(grouperGateLabel);
		
		grouperOutputLabel = new JLabel("Outputs");
		grouperOutputLabel.setBounds(130,45+395+6,60,20);
		grouperOutputLabel.setForeground(Color.lightGray);
		otherPanel.add(grouperOutputLabel);
		
		NumberFormatter numF = new NumberFormatter();
		numF.setAllowsInvalid(false);
		numF.setOverwriteMode(true);
		numF.setMinimum(1);
        numF.setMaximum(new Integer(99));
        
        grouperGateOutputTextField = new JFormattedTextField(numF);
		grouperGateOutputTextField.setBounds(108,45+395+6,20,20);
		grouperGateOutputTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		grouperGateOutputTextField.setValue(2);
		grouperGateOutputTextField.selectAll();
		grouperGateOutputTextField.addKeyListener(this);
		
		updateGrouperGateOutput(2);
		
		otherPanel.add(grouperGateOutputTextField);
		
		grouperInputLabel = new JLabel("Split-Top");
		grouperInputLabel.setBounds(128,45+420+6,60,20);
		grouperInputLabel.setForeground(Color.lightGray);
		otherPanel.add(grouperInputLabel);
		
        grouperGateInputTextField = new JFormattedTextField(numF);
		grouperGateInputTextField.setBounds(108,45+420+6,20,20);
		grouperGateInputTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray,2));
		grouperGateInputTextField.setValue(1);
		grouperGateInputTextField.selectAll();
		grouperGateInputTextField.addKeyListener(this);
		
		updateGrouperGateInput(1);
		
		otherPanel.add(grouperGateInputTextField);
	}
	/**
	 * Hides the AND Gate items displayed on the ComponentPanel.
	 */
	public void hideAndGateItems(){
		andGateComponent.setVisible(false);
		andInputLabel.setVisible(false);
		andGateTextField.setVisible(false);
		andGateLabel.setVisible(false);
	}
	/**
	 * Shows the AND Gate items displayed on the ComponentPanel.
	 */
	public void showAndGateItems(){
		andGateComponent.setVisible(true);
		andInputLabel.setVisible(true);
		andGateTextField.setVisible(true);
		andGateLabel.setVisible(true);
	}
	/**
	 * Hides the OR Gate items displayed on the ComponentPanel.
	 */
	public void hideOrGateItems(){
		orGateComponent.setVisible(false);
		orInputLabel.setVisible(false);
		orGateTextField.setVisible(false);
		orGateLabel.setVisible(false);
	}
	/**
	 * Shows the OR Gate items displayed on the ComponentPanel.
	 */
	public void showOrGateItems(){
		orGateComponent.setVisible(true);
		orInputLabel.setVisible(true);
		orGateTextField.setVisible(true);
		orGateLabel.setVisible(true);
	}
	/**
	 * Hides the NAND Gate items displayed on the ComponentPanel.
	 */
	public void hideNandGateItems(){
		nandGateComponent.setVisible(false);
		nandInputLabel.setVisible(false);
		nandGateTextField.setVisible(false);
		nandGateLabel.setVisible(false);
	}
	/**
	 * Shows the NAND Gate items displayed on the ComponentPanel.
	 */
	public void showNandGateItems(){
		nandGateComponent.setVisible(true);
		nandInputLabel.setVisible(true);
		nandGateTextField.setVisible(true);
		nandGateLabel.setVisible(true);
	}
	/**
	 * Hides the NOR Gate items displayed on the ComponentPanel.
	 */
	public void hideNorGateItems(){
		norGateComponent.setVisible(false);
		norInputLabel.setVisible(false);
		norGateTextField.setVisible(false);
		norGateLabel.setVisible(false);
	}
	/**
	 * Shows the NOR Gate items displayed on the ComponentPanel.
	 */
	public void showNorGateItems(){
		norGateComponent.setVisible(true);
		norInputLabel.setVisible(true);
		norGateTextField.setVisible(true);
		norGateLabel.setVisible(true);
	}
	/**
	 * Hides the NOT Gate items displayed on the ComponentPanel.
	 */
	public void hideNotGateItems(){
		notGateComponent.setVisible(false);
		notGateLabel.setVisible(false);
	}
	/**
	 * Shows the NOT Gate items displayed on the ComponentPanel.
	 */
	public void showNotGateItems(){
		notGateComponent.setVisible(true);
		notGateLabel.setVisible(true);
	}
	/**
	 * Hides the BUFFER Gate items displayed on the ComponentPanel.
	 */
	public void hideBufferGateItems(){
		bufferGateComponent.setVisible(false);
		bufferGateLabel.setVisible(false);
	}
	/**
	 * Shows the BUFFER Gate items displayed on the ComponentPanel.
	 */
	public void showBufferGateItems(){
		bufferGateComponent.setVisible(true);
		bufferGateLabel.setVisible(true);
	}
	/**
	 * Hides the XOR Gate items displayed on the ComponentPanel.
	 */
	public void hideXOrGateItems(){
		xorGateComponent.setVisible(false);
		xorInputLabel.setVisible(false);
		xorGateTextField.setVisible(false);
		xorGateLabel.setVisible(false);
	}
	/**
	 * Shows the XOR Gate items displayed on the ComponentPanel.
	 */
	public void showXOrGateItems(){
		xorGateComponent.setVisible(true);
		xorInputLabel.setVisible(true);
		xorGateTextField.setVisible(true);
		xorGateLabel.setVisible(true);
	}
	/**
	 * Hides the XNOR Gate items displayed on the ComponentPanel.
	 */
	public void hideXNorGateItems(){
		xnorGateComponent.setVisible(false);
		xnorInputLabel.setVisible(false);
		xnorGateTextField.setVisible(false);
		xnorGateLabel.setVisible(false);
	}
	/**
	 * Shows the XNOR Gate items displayed on the ComponentPanel.
	 */
	public void showXNorGateItems(){
		xnorGateComponent.setVisible(true);
		xnorInputLabel.setVisible(true);
		xnorGateTextField.setVisible(true);
		xnorGateLabel.setVisible(true);
	}
	/**
	 * Hides the SPLITTER Gate items displayed on the ComponentPanel.
	 */
	public void hideSplitterGateItems(){
		splitterGateComponent.setVisible(false);
		splitterInputLabel.setVisible(false);
		splitterOutputLabel.setVisible(false);
		splitterGateInputTextField.setVisible(false);
		splitterGateOutputTextField.setVisible(false);
		splitterGateLabel.setVisible(false);
	}
	/**
	 * Shows the SPLITTER Gate items displayed on the ComponentPanel.
	 */
	public void showSplitterGateItems(){
		splitterGateComponent.setVisible(true);
		splitterInputLabel.setVisible(true);
		splitterOutputLabel.setVisible(true);
		splitterGateInputTextField.setVisible(true);
		splitterGateOutputTextField.setVisible(true);
		splitterGateLabel.setVisible(true);
	}
	/**
	 * Hides the GROUPER Gate items displayed on the ComponentPanel.
	 */
	public void hideGrouperGateItems(){
		grouperGateComponent.setVisible(false);
		grouperInputLabel.setVisible(false);
		grouperOutputLabel.setVisible(false);
		grouperGateInputTextField.setVisible(false);
		grouperGateOutputTextField.setVisible(false);
		grouperGateLabel.setVisible(false);
	}
	/**
	 * Shows the GROUPER Gate items displayed on the ComponentPanel.
	 */
	public void showGrouperGateItems(){
		grouperGateComponent.setVisible(true);
		grouperInputLabel.setVisible(true);
		grouperOutputLabel.setVisible(true);
		grouperGateInputTextField.setVisible(true);
		grouperGateOutputTextField.setVisible(true);
		grouperGateLabel.setVisible(true);
	}
	
	@Override
	public void mouseClicked(MouseEvent arg0) {}
	@Override
	public void mouseEntered(MouseEvent arg0) {}
	@Override
	public void mouseExited(MouseEvent arg0) {}
	@Override
	public void mousePressed(MouseEvent arg0) {
		
		mg.getAboutPanel().setVisible(false);
		
		if(arg0.getSource()==andGateTrigger){
			loseFocus();
			andGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			nandGateTrigger.setBackground(Color.white);
			showAndGateItems();
			hideNandGateItems();
			
			andGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			andGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			
			mg.getActions().setActionToAddANDGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==orGateTrigger){
			loseFocus();
			orGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			norGateTrigger.setBackground(Color.white);
			showOrGateItems();
			hideNorGateItems();
			
			orGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			orGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			
			mg.getActions().setActionToAddORGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==nandGateTrigger){
			loseFocus();
			nandGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			andGateTrigger.setBackground(Color.white);
			showNandGateItems();
			hideAndGateItems();
			
			nandGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			nandGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			
			mg.getActions().setActionToAddNANDGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==norGateTrigger){
			loseFocus();
			norGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			orGateTrigger.setBackground(Color.white);
			showNorGateItems();
			hideOrGateItems();
			
			norGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			norGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			
			mg.getActions().setActionToAddNORGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==bufferGateTrigger){
			loseFocus();
			bufferGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			notGateTrigger.setBackground(Color.white);
			showBufferGateItems();
			hideNotGateItems();
			
			bufferGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			bufferGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			
			mg.getActions().setActionToAddBUFFERGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==notGateTrigger){
			loseFocus();
			notGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			bufferGateTrigger.setBackground(Color.white);
			showNotGateItems();
			hideBufferGateItems();
			
			notGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			notGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			
			mg.getActions().setActionToAddNOTGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==xorGateTrigger){
			loseFocus();
			xorGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			xnorGateTrigger.setBackground(Color.white);
			showXOrGateItems();
			hideXNorGateItems();
			
			xorGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			xorGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			
			mg.getActions().setActionToAddXORGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==xnorGateTrigger){
			loseFocus();
			xnorGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			xorGateTrigger.setBackground(Color.white);
			showXNorGateItems();
			hideXOrGateItems();
			
			xnorGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			xnorGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			
			mg.getActions().setActionToAddXNORGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==splitterGateTrigger){
			loseFocus();
			splitterGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			grouperGateTrigger.setBackground(Color.white);
			showSplitterGateItems();
			hideGrouperGateItems();
			
			splitterGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			splitterGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			
			mg.getActions().setActionToAddSplitterGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusOtherTab();
			mg.repaint();
		}
		if(arg0.getSource()==grouperGateTrigger){
			loseFocus();
			grouperGateTrigger.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			splitterGateTrigger.setBackground(Color.white);
			showGrouperGateItems();
			hideSplitterGateItems();
			
			grouperGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			grouperGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			
			mg.getActions().setActionToAddGrouperGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusOtherTab();
			mg.repaint();
		}
		if(arg0.getSource()==andGateTransparentSheet){
			loseFocus();
			andGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			andGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddANDGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==orGateTransparentSheet){
			loseFocus();
			orGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			orGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddORGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==nandGateTransparentSheet){
			loseFocus();
			nandGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			nandGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddNANDGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==norGateTransparentSheet){
			loseFocus();
			norGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			norGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddNORGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==bufferGateTransparentSheet){
			loseFocus();
			bufferGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			bufferGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddBUFFERGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		
		if(arg0.getSource()==notGateTransparentSheet){
			loseFocus();
			notGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			notGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddNOTGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==xorGateTransparentSheet){
			loseFocus();
			xorGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			xorGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddXORGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==xnorGateTransparentSheet){
			loseFocus();
			xnorGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			xnorGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddXNORGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==tsbufferGateTransparentSheet){
			loseFocus();
			tsbufferGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			tsbufferGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddTSBUFFERGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==dffGateTransparentSheet){
			loseFocus();
			dffGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			dffGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddDFFGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusFFTab();
			mg.repaint();
		}
		if(arg0.getSource()==tffGateTransparentSheet){
			loseFocus();
			tffGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			tffGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddTFFGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusFFTab();
			mg.repaint();
		}
		if(arg0.getSource()==jkffGateTransparentSheet){
			loseFocus();
			jkffGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			jkffGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddJKFFGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusFFTab();
			mg.repaint();
		}
		if(arg0.getSource()==srffGateTransparentSheet){
			loseFocus();
			srffGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			srffGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddSRFFGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusFFTab();
			mg.repaint();
		}
		if(arg0.getSource()==customGateTransparentSheet){
			loseFocus();
			customGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			customGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddCustomGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusOtherTab();
			mg.repaint();
		}
		if(arg0.getSource()==textGateTransparentSheet){
			loseFocus();
			textGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			textGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddTextGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusOtherTab();
			mg.repaint();
		}
		if(arg0.getSource()==moduleGateTransparentSheet){
			loseFocus();
			moduleGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			moduleGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddModuleGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusOtherTab();
			mg.repaint();
		}
		if(arg0.getSource()==showModuleImageCheckBox){
			
			drawModuleGateComponent(importedFile,!showModuleImageCheckBox.isSelected());
			mg.focusOtherTab();
			mg.repaint();
			repaint();
		}
		if(arg0.getSource()==showCustomCheckBox){
			
			drawCustomGateComponent(mg.getComponentPanel().getCustomComponent().getNumberOfInputs(),
					mg.getComponentPanel().getCustomComponent().getNumberOfOutputs(),
					mg.getComponentPanel().getCustomComponent().getComponentText(),
					mg.getComponentPanel().getCustomComponent().getClockPin(),
					!showCustomCheckBox.isSelected());
			mg.focusOtherTab();
			mg.repaint();
			repaint();
		}
		if(arg0.getSource()==moduleImportButton){
			
			JFileChooser jf = new JFileChooser();
			jf.setDialogTitle("Import File");
			jf.addChoosableFileFilter(new SBFileFilter());
			jf.setVisible(true);
			
			try{
				
				if (jf.showDialog(null,"Import") == JFileChooser.APPROVE_OPTION)
				{
					importedFile = jf.getSelectedFile();
				}
				
				String path = importedFile.getAbsolutePath();
				if(!path.endsWith(".sb")){
					importedFile = new File(path + ".sb");
				}
			}
			catch (Exception e){}
			drawModuleGateComponent(importedFile,showModuleImageCheckBox.isSelected());
			mg.focusOtherTab();
			mg.repaint();
		}
		if(arg0.getSource()==wireComponent){
			loseFocus();
			wireComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			wireComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddWire();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==wireComponent2){
			loseFocus();
			wireComponent2.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			wireComponent2.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddWire();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusFFTab();
			mg.repaint();
		}
		if(arg0.getSource()==wireComponent3){
			loseFocus();
			wireComponent3.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			wireComponent3.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddWire();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusOtherTab();
			mg.repaint();
		}
		if(arg0.getSource()==nodeGateTransparentSheet){
			loseFocus();
			nodeGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			nodeGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddNodeComponent();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==nodeGateTransparentSheet2){
			loseFocus();
			nodeGateComponent2.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			nodeGateComponent2.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddNodeComponent();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusFFTab();
			mg.repaint();
		}
		if(arg0.getSource()==nodeGateTransparentSheet3){
			loseFocus();
			nodeGateComponent3.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			nodeGateComponent3.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddNodeComponent();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusOtherTab();
			mg.repaint();
		}
		if(arg0.getSource()==splitterGateTransparentSheet){
			loseFocus();
			splitterGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			splitterGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddSplitterGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusOtherTab();
			mg.repaint();
		}
		if(arg0.getSource()==grouperGateTransparentSheet){
			loseFocus();
			grouperGateComponent.setBackground(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
			grouperGateComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray,3));
			mg.getActions().setActionToAddGrouperGate();
			mg.getActionPanel().loseFocus();
			mg.getWorkArea().deselectAllComponents();
			mg.getWorkArea().hideSelectionBox();
			mg.focusOtherTab();
			mg.repaint();
		}
		if(arg0.getSource()==basicPanel){
			loseFocus();
			mg.getActions().setActionToNothing();
			mg.focusBasicTab();
			mg.repaint();
		}
		if(arg0.getSource()==ffPanel){
			loseFocus();
			mg.getActions().setActionToNothing();
			mg.focusFFTab();
			mg.repaint();
		}
		if(arg0.getSource()==otherPanel){
			loseFocus();
			mg.getActions().setActionToNothing();
			mg.focusOtherTab();
			mg.repaint();
		}
		repaint();
	}
	@Override
	public void mouseReleased(MouseEvent arg0) {}
	@Override
	public void keyPressed(KeyEvent e) {
		if(e.getSource()==andGateTextField){
			mg.focusBasicTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				andGateTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(andGateTextField.getText())>1){
						drawAndGateComponent(Integer.parseInt(andGateTextField.getText()));
						
					}
					else{
						andGateTextField.setValue(null);
					}
				}
				catch(Exception ex){}
			}
		}
		if(e.getSource()==orGateTextField){
			mg.focusBasicTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				orGateTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(orGateTextField.getText())>1){
						drawOrGateComponent(Integer.parseInt(orGateTextField.getText()));
						
					}
					else{
						orGateTextField.setValue(null);
					}
				}
				catch(Exception ex){}
			}
		}
		if(e.getSource()==nandGateTextField){
			mg.focusBasicTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				nandGateTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				if(Integer.parseInt(nandGateTextField.getText())>1){
					try{
						drawNandGateComponent(Integer.parseInt(nandGateTextField.getText()));
						
					}
					catch(Exception ex){}
				}
				else{
					nandGateTextField.setValue(null);
				}
			}
		}
		if(e.getSource()==norGateTextField){
			mg.focusBasicTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				norGateTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				if(Integer.parseInt(norGateTextField.getText())>1){
					try{
						drawNorGateComponent(Integer.parseInt(norGateTextField.getText()));
						
					}
					catch(Exception ex){}
				}
				else{
					norGateTextField.setValue(null);
				}
			}
		}
		if(e.getSource()==xorGateTextField){
			mg.focusBasicTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				xorGateTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(xorGateTextField.getText())>1){
						drawXorGateComponent(Integer.parseInt(xorGateTextField.getText()));
						
					}
					else{
						xorGateTextField.setValue(null);
					}
				}
				catch(Exception ex){}
			}
		}
		if(e.getSource()==xnorGateTextField){
			mg.focusBasicTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				xnorGateTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				if(Integer.parseInt(xnorGateTextField.getText())>1){
					try{
						drawXnorGateComponent(Integer.parseInt(xnorGateTextField.getText()));
						
					}
					catch(Exception ex){}
				}
				else{
					xnorGateTextField.setValue(null);
				}
			}
		}
		if(e.getSource()==customGateInputTextField){
			mg.focusOtherTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				customGateInputTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(customGateInputTextField.getText())>0){
						drawCustomGateComponent(Integer.parseInt(customGateInputTextField.getText()),
						mg.getComponentPanel().getCustomComponent().getNumberOfOutputs(),
						mg.getComponentPanel().getCustomComponent().getComponentText(),
						mg.getComponentPanel().getCustomComponent().getClockPin(),
						mg.getComponentPanel().getCustomComponent().getShowDetailsValue());
					}
					else{
						customGateInputTextField.setValue(null);
					}
				}
					catch(Exception ex){}
			}
		}
		if(e.getSource()==customGateOutputTextField){
			mg.focusOtherTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				customGateOutputTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(customGateOutputTextField.getText())>0){
						drawCustomGateComponent(mg.getComponentPanel().getCustomComponent().getNumberOfInputs(),
								Integer.parseInt(customGateOutputTextField.getText()),
								mg.getComponentPanel().getCustomComponent().getComponentText(),
								mg.getComponentPanel().getCustomComponent().getClockPin(),
								mg.getComponentPanel().getCustomComponent().getShowDetailsValue());
					}
					else{
						customGateOutputTextField.setValue(null);
					}
				}
				catch(Exception ex){}
			}
		}
		if(e.getSource()==customGateTitleTextField){
			mg.focusOtherTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				
				drawCustomGateComponent(mg.getComponentPanel().getCustomComponent().getNumberOfInputs(),
						mg.getComponentPanel().getCustomComponent().getNumberOfOutputs(),
						customGateTitleTextField.getText().replaceAll(" ",""),
						mg.getComponentPanel().getCustomComponent().getClockPin(),
						mg.getComponentPanel().getCustomComponent().getShowDetailsValue());
			}
		}
		if(e.getSource()==customGateClockPinTextField){
			mg.focusOtherTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				customGateClockPinTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					int pin =Integer.parseInt(customGateClockPinTextField.getText());
					if(pin>getCustomComponent().getNumberOfInputs()){
						pin=0;
						customGateClockPinTextField.setText(0+"");
					}
					drawCustomGateComponent(getCustomComponent().getNumberOfInputs(),
							getCustomComponent().getNumberOfOutputs(),
							getCustomComponent().getComponentText(),
							Integer.parseInt(customGateClockPinTextField.getText()),
							mg.getComponentPanel().getCustomComponent().getShowDetailsValue());
				
				}
				catch(Exception ex){}
			}
		}
		if(e.getSource()==textGateTitleTextField){
			mg.focusOtherTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				
				drawTextGateComponent(textGateTitleTextField.getText().replaceAll(" ",""));
			}
		}
		if(e.getSource()==nodeGateTextField){
			mg.focusBasicTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				nodeGateTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(nodeGateTextField.getText())>0){
						nodeGateTextField2.setValue(Integer.parseInt(nodeGateTextField.getText()));
						nodeGateTextField3.setValue(Integer.parseInt(nodeGateTextField.getText()));
						drawNodeGateComponent(Integer.parseInt(nodeGateTextField.getText()));
						drawNodeGate2Component(Integer.parseInt(nodeGateTextField.getText()));
						drawNodeGate3Component(Integer.parseInt(nodeGateTextField.getText()));
					}
					else{
						nodeGateTextField.setValue(1);
						nodeGateTextField2.setValue(1);
						nodeGateTextField3.setValue(1);
						drawNodeGateComponent(1);
						drawNodeGate2Component(1);
						drawNodeGate3Component(1);
					}
				}
				catch(Exception ex){}	
			}
		}
		if(e.getSource()==nodeGateTextField2){
			mg.focusFFTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				nodeGateTextField2.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(nodeGateTextField2.getText())>0){
						nodeGateTextField.setValue(Integer.parseInt(nodeGateTextField2.getText()));
						nodeGateTextField3.setValue(Integer.parseInt(nodeGateTextField2.getText()));
						drawNodeGateComponent(Integer.parseInt(nodeGateTextField2.getText()));
						drawNodeGate2Component(Integer.parseInt(nodeGateTextField2.getText()));
						drawNodeGate3Component(Integer.parseInt(nodeGateTextField2.getText()));
					}
					else{
						nodeGateTextField.setValue(1);
						nodeGateTextField2.setValue(1);
						nodeGateTextField3.setValue(1);
						drawNodeGateComponent(1);
						drawNodeGate2Component(1);
						drawNodeGate3Component(1);
					}
				}
				catch(Exception ex){}
			}
		}
		if(e.getSource()==nodeGateTextField3){
			mg.focusOtherTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				nodeGateTextField3.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(nodeGateTextField3.getText())>0){
						nodeGateTextField.setValue(Integer.parseInt(nodeGateTextField3.getText()));
						nodeGateTextField2.setValue(Integer.parseInt(nodeGateTextField3.getText()));
						drawNodeGateComponent(Integer.parseInt(nodeGateTextField3.getText()));
						drawNodeGate2Component(Integer.parseInt(nodeGateTextField3.getText()));
						drawNodeGate3Component(Integer.parseInt(nodeGateTextField3.getText()));
					}
					else{
						nodeGateTextField.setValue(1);
						nodeGateTextField2.setValue(1);
						nodeGateTextField3.setValue(1);
						drawNodeGateComponent(1);
						drawNodeGate2Component(1);
						drawNodeGate3Component(1);
					}
				}
				catch(Exception ex){}
			}
		}
		if(e.getSource()==splitterGateInputTextField){
			mg.focusOtherTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				splitterGateInputTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(splitterGateInputTextField.getText())<2){
						splitterGateInputTextField.setValue(2);
						updateSplitterGateInput(2);
					}
					else{
						updateSplitterGateInput(Integer.parseInt(splitterGateInputTextField.getText()));
					}
					
					if(getSplitterGateOutput()>=getSplitterGateInput()){
						updateSplitterGateOutput(getSplitterGateInput()-1);
						splitterGateOutputTextField.setValue(getSplitterGateInput()-1);
					}
				}
				catch(Exception ex){}
			}
		}
		if(e.getSource()==splitterGateOutputTextField){
			mg.focusOtherTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				splitterGateOutputTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(splitterGateOutputTextField.getText())>=getSplitterGateInput()){
						splitterGateOutputTextField.setValue(getSplitterGateInput()-1);
						updateSplitterGateOutput(getSplitterGateInput()-1);
					}
					else{
						updateSplitterGateOutput(Integer.parseInt(splitterGateOutputTextField.getText()));
					}
				}
				catch(Exception ex){}
			}
		}
		if(e.getSource()==grouperGateOutputTextField){
			mg.focusOtherTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				grouperGateOutputTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(grouperGateOutputTextField.getText())<2){
						grouperGateOutputTextField.setValue(2);
						updateGrouperGateOutput(2);
					}
					else{
						updateGrouperGateOutput(Integer.parseInt(grouperGateOutputTextField.getText()));
					}
					
					if(getGrouperGateInput()>=getGrouperGateOutput()){
						updateGrouperGateInput(getGrouperGateOutput()-1);
						grouperGateInputTextField.setValue(getGrouperGateOutput()-1);
					}
				}
				catch(Exception ex){}
			}
		}
		if(e.getSource()==grouperGateInputTextField){
			mg.focusOtherTab();
			mg.repaint();
			if(e.getKeyCode()==KeyEvent.VK_BACK_SPACE ||e.getKeyCode()==KeyEvent.VK_DELETE){
				grouperGateInputTextField.setValue(null);
			}
			if(e.getKeyCode()==KeyEvent.VK_ENTER){
				try{
					if(Integer.parseInt(grouperGateInputTextField.getText())>=getGrouperGateOutput()){
						grouperGateInputTextField.setValue(getGrouperGateOutput()-1);
						updateGrouperGateInput(getGrouperGateOutput()-1);
					}
					else{
						updateGrouperGateInput(Integer.parseInt(grouperGateInputTextField.getText()));
					}
				}
				catch(Exception ex){}
			}
		}
	}
	@Override
	public void keyReleased(KeyEvent e) {}
	@Override
	public void keyTyped(KeyEvent e) {}

}
